package com.infoyoung.firework.dao.impl;

import java.util.Date;

import com.infoyoung.firework.dao.IFireworkTagDao;
import com.infoyoung.firework.pojo.FireworkTagPo;
import com.litt.core.common.Utility;
import com.litt.core.dao.BaseDaoImpl;
import com.litt.core.page.IPageList;
import com.litt.core.page.PagePoParam;
import com.litt.core.util.ParamUtils;

/**
 * <b>标题：</b>烟花管理DAO实现.
 * <pre><b>描述</b>
 *    烟花管理
 * </pre>
 * 
 * @author caiyuan
 * @since 2008-6-13
 * @version 1.0
 *
 */
public class FireworkTagDaoImpl extends BaseDaoImpl implements IFireworkTagDao 
{
	/**
	 * 根据类型统计数量
	 * @param dataType 数据类型
	 * @return 统计数量
	 */
	public int countByDataType(Long dataType)
	{
		StringBuffer listCountHql = new StringBuffer("select count(*) from TfireworkTag where 1=1");
		//查询条件
		listCountHql.append(" and dataType=?");
		
		return super.listHqlCount(listCountHql.toString(), new Object[]{dataType});
	}
	
	
	/**
	 * 分页查询.
	 * 
	 * @param pagePoParam 查询参数
	 * @return IPageList IPageList对象
	 */
	public IPageList listByPage(PagePoParam pagePoParam) 
	{
		FireworkTagPo fireworkTagPo = (FireworkTagPo)pagePoParam.getConds();
		Long dataType = fireworkTagPo.getDataType();
		String dataName = fireworkTagPo.getDataName()+"%";
		Date startDate = Utility.parseDate(fireworkTagPo.getStartDate(), new Date());
		Date endDate = Utility.parseDate(fireworkTagPo.getEndDate(), new Date());
		
		StringBuffer listHql = new StringBuffer("from TfireworkTag where 1=1");
		StringBuffer listCountHql = new StringBuffer("select count(*) from TfireworkTag where 1=1");
		//查询条件
		listHql.append(" and dataType=?");
		listCountHql.append(" and dataType=?");
		
		listHql.append(" and dataName like ?");
		listCountHql.append(" and dataName like ?");			
		
		listHql.append(" and dataDate>=? and dataDate<=?");
		listCountHql.append(" and dataDate>=? and dataDate<=?");
		
		return super.listHqlPage(listHql.toString(), listCountHql.toString(),new Object[]{dataType,dataName,startDate,endDate},pagePoParam.getPageIndex(), pagePoParam.getPageSize());
	}
}
